<?php

namespace App\Common\Dao\System;

use App\Common\Dao\BaseDao;
use App\Model\CustomerDepartments;

class CustomerDepartmentsDao extends BaseDao
{
    protected function getModel(): CustomerDepartments
    {
        return new CustomerDepartments();
    }

    public function search(array $where){
        return CustomerDepartments::when(isset($where['status']) && $where['status'] != ''  , function ($query) use ($where) {
            $query->where('status', $where['status']);
        })
            ->when(isset($where['department_name']) && $where['department_name'] != ''  , function ($query) use ($where) {
                $query->where('department_name', 'like', "%" .$where['department_name']. "%");
            })
            ->when(isset($where['email']) && $where['email'] != ''  , function ($query) use ($where) {
                $query->where('email', 'like', "%" .$where['email']. "%");
            });
    }
}